import numpy as np
import cv2 as cv

cap = cv.VideoCapture('d5.mp4')
fourcc = cv.VideoWriter_fourcc(*'XVID')
out = cv.VideoWriter('d5_out.avi', fourcc, 20.0, (1280, 720))

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        print('can not read frame, exiting')
        break

    frame = cv.flip(frame, 0)
    out.write(frame)
    cv.imshow('frame', frame)
    if cv.waitKey(40) == ord('q'):
        break

cap.release()
out.release()
cv.destroyAllWindows()